//
//  LCMainTabBarController.swift
//  SinaWeiBo
//
//  Created by mac on 16/11/30.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

class LCMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //添加自控制器的两种方式
        //viewControllers
        //addChildViewController(<#T##childController: UIViewController##UIViewController#>)
        
        //1设置自定义tabbar
        let tabBarView = LCTabBarView()
        setValue(tabBarView, forKey: "tabBar")
        //设置代理
        tabBarView.lcDelegate = self
        
        
        //2实现闭包
        tabBarView.cellBack = {
            //点击发微博按钮的操作
            //1获取windows中最上边的一个window
            let composeView = LCComposeView()
            composeView.show(taget:self)
        
        }
        
        //添加自控制器
        addChildViewController(childController: LCHomeController(), title: "主页", imageName: "tabbar_home")
        addChildViewController(childController: LCDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: LCMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: LCProfileController(), title: "我的", imageName: "tabbar_profile")
    }
    //重载添加tabBar控制器
    func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        //1设置tabbar的现实图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        //2设置字体颜色和大小
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 12)], for: .normal)
        //3设置tabbar的title
        childController.title = title
        //4创建navigatoncontroller
        let naVc = LCNavigationController(rootViewController: childController)
        //5添加到tabbarController
        addChildViewController(naVc)
    }

}
//遵守代理实现代理方法/extension方法可以扩展tabbar类
extension LCMainTabBarController: LCTabBarViewDelegate{
    
    func clickButton() {
        print("代理回来了")
    }
    
}





